﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
	/// <summary>
	/// 数据访问类:T_WorkPracticeExamSubject
	/// </summary>
	public partial class T_WorkPracticeExamSubject
	{
		public T_WorkPracticeExamSubject()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Model.T_WorkPracticeExamSubject model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_WorkPracticeExamSubject(");
			strSql.Append("ExamID,ExamGUID,SubjectID,SubjectTitle,Descrip,VideoPath,UserAnswer,StandardAnswer,IsRight,AnswerAnalysis,GroupId,GroupName,Knowledge,LevelOfDifficulty,EvaluatorCode,EvaluatorName)");
			strSql.Append(" values (");
			strSql.Append("@ExamID,@ExamGUID,@SubjectID,@SubjectTitle,@Descrip,@VideoPath,@UserAnswer,@StandardAnswer,@IsRight,@AnswerAnalysis,@GroupId,@GroupName,@Knowledge,@LevelOfDifficulty,@EvaluatorCode,@EvaluatorName)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamID", SqlDbType.Int,4),
					new SqlParameter("@ExamGUID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@SubjectID", SqlDbType.Int,4),
					new SqlParameter("@SubjectTitle", SqlDbType.NVarChar,500),
					new SqlParameter("@Descrip", SqlDbType.Text),
					new SqlParameter("@VideoPath", SqlDbType.VarChar,200),
					new SqlParameter("@UserAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@StandardAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@IsRight", SqlDbType.Int,4),
					new SqlParameter("@AnswerAnalysis", SqlDbType.NVarChar,50),
					new SqlParameter("@GroupId", SqlDbType.Int,4),
					new SqlParameter("@GroupName", SqlDbType.NVarChar,50),
					new SqlParameter("@Knowledge", SqlDbType.NVarChar,50),
					new SqlParameter("@LevelOfDifficulty", SqlDbType.NChar,10),
					new SqlParameter("@EvaluatorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@EvaluatorName", SqlDbType.NVarChar,50)};
			parameters[0].Value = model.ExamID;
			parameters[1].Value = Guid.NewGuid();
			parameters[2].Value = model.SubjectID;
			parameters[3].Value = model.SubjectTitle;
			parameters[4].Value = model.Descrip;
			parameters[5].Value = model.VideoPath;
			parameters[6].Value = model.UserAnswer;
			parameters[7].Value = model.StandardAnswer;
			parameters[8].Value = model.IsRight;
			parameters[9].Value = model.AnswerAnalysis;
			parameters[10].Value = model.GroupId;
			parameters[11].Value = model.GroupName;
			parameters[12].Value = model.Knowledge;
			parameters[13].Value = model.LevelOfDifficulty;
			parameters[14].Value = model.EvaluatorCode;
			parameters[15].Value = model.EvaluatorName;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.T_WorkPracticeExamSubject model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_WorkPracticeExamSubject set ");
			strSql.Append("ExamID=@ExamID,");
			strSql.Append("ExamGUID=@ExamGUID,");
			strSql.Append("SubjectID=@SubjectID,");
			strSql.Append("SubjectTitle=@SubjectTitle,");
			strSql.Append("Descrip=@Descrip,");
			strSql.Append("VideoPath=@VideoPath,");
			strSql.Append("UserAnswer=@UserAnswer,");
			strSql.Append("StandardAnswer=@StandardAnswer,");
			strSql.Append("IsRight=@IsRight,");
			strSql.Append("AnswerAnalysis=@AnswerAnalysis,");
			strSql.Append("GroupId=@GroupId,");
			strSql.Append("GroupName=@GroupName,");
			strSql.Append("Knowledge=@Knowledge,");
			strSql.Append("LevelOfDifficulty=@LevelOfDifficulty,");
			strSql.Append("EvaluatorCode=@EvaluatorCode,");
			strSql.Append("EvaluatorName=@EvaluatorName");
			strSql.Append(" where W_PracticeExamSubjectId=@W_PracticeExamSubjectId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamID", SqlDbType.Int,4),
					new SqlParameter("@ExamGUID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@SubjectID", SqlDbType.Int,4),
					new SqlParameter("@SubjectTitle", SqlDbType.NVarChar,500),
					new SqlParameter("@Descrip", SqlDbType.Text),
					new SqlParameter("@VideoPath", SqlDbType.VarChar,200),
					new SqlParameter("@UserAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@StandardAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@IsRight", SqlDbType.Int,4),
					new SqlParameter("@AnswerAnalysis", SqlDbType.NVarChar,50),
					new SqlParameter("@GroupId", SqlDbType.Int,4),
					new SqlParameter("@GroupName", SqlDbType.NVarChar,50),
					new SqlParameter("@Knowledge", SqlDbType.NVarChar,50),
					new SqlParameter("@LevelOfDifficulty", SqlDbType.NChar,10),
					new SqlParameter("@EvaluatorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@EvaluatorName", SqlDbType.NVarChar,50),
					new SqlParameter("@W_PracticeExamSubjectId", SqlDbType.Int,4)};
			parameters[0].Value = model.ExamID;
			parameters[1].Value = model.ExamGUID;
			parameters[2].Value = model.SubjectID;
			parameters[3].Value = model.SubjectTitle;
			parameters[4].Value = model.Descrip;
			parameters[5].Value = model.VideoPath;
			parameters[6].Value = model.UserAnswer;
			parameters[7].Value = model.StandardAnswer;
			parameters[8].Value = model.IsRight;
			parameters[9].Value = model.AnswerAnalysis;
			parameters[10].Value = model.GroupId;
			parameters[11].Value = model.GroupName;
			parameters[12].Value = model.Knowledge;
			parameters[13].Value = model.LevelOfDifficulty;
			parameters[14].Value = model.EvaluatorCode;
			parameters[15].Value = model.EvaluatorName;
			parameters[16].Value = model.W_PracticeExamSubjectId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int W_PracticeExamSubjectId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_WorkPracticeExamSubject ");
			strSql.Append(" where W_PracticeExamSubjectId=@W_PracticeExamSubjectId");
			SqlParameter[] parameters = {
					new SqlParameter("@W_PracticeExamSubjectId", SqlDbType.Int,4)
			};
			parameters[0].Value = W_PracticeExamSubjectId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string W_PracticeExamSubjectIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_WorkPracticeExamSubject ");
			strSql.Append(" where W_PracticeExamSubjectId in ("+W_PracticeExamSubjectIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkPracticeExamSubject GetModel(int W_PracticeExamSubjectId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 W_PracticeExamSubjectId,ExamID,ExamGUID,SubjectID,SubjectTitle,Descrip,VideoPath,UserAnswer,StandardAnswer,IsRight,AnswerAnalysis,GroupId,GroupName,Knowledge,LevelOfDifficulty,EvaluatorCode,EvaluatorName from T_WorkPracticeExamSubject ");
			strSql.Append(" where W_PracticeExamSubjectId=@W_PracticeExamSubjectId");
			SqlParameter[] parameters = {
					new SqlParameter("@W_PracticeExamSubjectId", SqlDbType.Int,4)
			};
			parameters[0].Value = W_PracticeExamSubjectId;

			Model.T_WorkPracticeExamSubject model=new Model.T_WorkPracticeExamSubject();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkPracticeExamSubject DataRowToModel(DataRow row)
		{
			Model.T_WorkPracticeExamSubject model=new Model.T_WorkPracticeExamSubject();
			if (row != null)
			{
				if(row["W_PracticeExamSubjectId"]!=null && row["W_PracticeExamSubjectId"].ToString()!="")
				{
					model.W_PracticeExamSubjectId=int.Parse(row["W_PracticeExamSubjectId"].ToString());
				}
				if(row["ExamID"]!=null && row["ExamID"].ToString()!="")
				{
					model.ExamID=int.Parse(row["ExamID"].ToString());
				}
				if(row["ExamGUID"]!=null && row["ExamGUID"].ToString()!="")
				{
					model.ExamGUID= new Guid(row["ExamGUID"].ToString());
				}
				if(row["SubjectID"]!=null && row["SubjectID"].ToString()!="")
				{
					model.SubjectID=int.Parse(row["SubjectID"].ToString());
				}
				if(row["SubjectTitle"]!=null)
				{
					model.SubjectTitle=row["SubjectTitle"].ToString();
				}
				if(row["Descrip"]!=null)
				{
					model.Descrip=row["Descrip"].ToString();
				}
				if(row["VideoPath"]!=null)
				{
					model.VideoPath=row["VideoPath"].ToString();
				}
				if(row["UserAnswer"]!=null)
				{
					model.UserAnswer=row["UserAnswer"].ToString();
				}
				if(row["StandardAnswer"]!=null)
				{
					model.StandardAnswer=row["StandardAnswer"].ToString();
				}
				if(row["IsRight"]!=null && row["IsRight"].ToString()!="")
				{
					model.IsRight=int.Parse(row["IsRight"].ToString());
				}
				if(row["AnswerAnalysis"]!=null)
				{
					model.AnswerAnalysis=row["AnswerAnalysis"].ToString();
				}
				if(row["GroupId"]!=null && row["GroupId"].ToString()!="")
				{
					model.GroupId=int.Parse(row["GroupId"].ToString());
				}
				if(row["GroupName"]!=null)
				{
					model.GroupName=row["GroupName"].ToString();
				}
				if(row["Knowledge"]!=null)
				{
					model.Knowledge=row["Knowledge"].ToString();
				}
				if(row["LevelOfDifficulty"]!=null)
				{
					model.LevelOfDifficulty=row["LevelOfDifficulty"].ToString();
				}
				if(row["EvaluatorCode"]!=null)
				{
					model.EvaluatorCode=row["EvaluatorCode"].ToString();
				}
				if(row["EvaluatorName"]!=null)
				{
					model.EvaluatorName=row["EvaluatorName"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select W_PracticeExamSubjectId,ExamID,ExamGUID,SubjectID,SubjectTitle,Descrip,VideoPath,UserAnswer,StandardAnswer,IsRight,AnswerAnalysis,GroupId,GroupName,Knowledge,LevelOfDifficulty,EvaluatorCode,EvaluatorName ");
			strSql.Append(" FROM T_WorkPracticeExamSubject ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" W_PracticeExamSubjectId,ExamID,ExamGUID,SubjectID,SubjectTitle,Descrip,VideoPath,UserAnswer,StandardAnswer,IsRight,AnswerAnalysis,GroupId,GroupName,Knowledge,LevelOfDifficulty,EvaluatorCode,EvaluatorName ");
			strSql.Append(" FROM T_WorkPracticeExamSubject ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_WorkPracticeExamSubject ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.W_PracticeExamSubjectId desc");
			}
			strSql.Append(")AS Row, T.*  from T_WorkPracticeExamSubject T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_WorkPracticeExamSubject";
			parameters[1].Value = "W_PracticeExamSubjectId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

